package com.ty.day5;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * Author : txy
 * Create 2023/11/1 14:10
 */
public class Three {
    public static void main(String[] args) {
        int[] a = new int[10];

        int k = 0, p = 0;
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < a.length; i++) {
            a[i] = random.nextInt(100) + 1;
//            a[i] = sc.nextInt();
        }
        int max, min;
        max = min = a[0];
        for (int value : a) {
            System.out.print(value + " ");
        }
        for (int i = 1; i < a.length; i++) {
            if (max < a[i]) {
                max = a[i];
                k = i;
            }
            if (min > a[i]) {
                min = a[i];
                p = i;
            }
        }
        if (k == a.length - 1 && p == 0) {
            a[0] = max;
        } else {
            a[k] = a[0];
            a[0] = max;
            a[p] = a[a.length - 1];
        }
        a[a.length - 1] = min;

        System.out.println("\n交换位置后：");
        for (int j : a) {
            System.out.print(j + " ");
        }


    }
}
